package com.lzy.web;

import com.lzy.po.BlogQuery;
import com.lzy.po.Tag;
import com.lzy.po.Type;
import com.lzy.service.BlogService;
import com.lzy.service.TagService;
import com.lzy.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @autor shkstart
 * @create 2021-01-07 21:50)
 */
@Controller
public class TagShowController {

    @Autowired
    private TagService tagService;

    @Autowired
    private BlogService blogService;

    @GetMapping("/tags/{id}")
    public String types(@PageableDefault(size = 8,sort = {"updateTime"},direction = Sort.Direction.DESC) Pageable pageable,
                        Model model,
                        @PathVariable("id") Long id){
        List<Tag> tags = tagService.listTag(10000);
        if (id == -1){
            id = tags.get(0).getId();
        }
        model.addAttribute("tags", tags);  //获取全部的标签
        model.addAttribute("page", blogService.listBlog(id,pageable));//获取选择标签的博客集合

        model.addAttribute("activeType",id); //用来高亮选中的类型
        return "tags";

    }
}
